﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlatRedBall;
using FlatRedBall.Math.Geometry;
using Microsoft.Xna.Framework;
using TopDownShooter.Screens;

namespace TopDownShooter
{
    class Bullet : PositionedObject
    {
        public Line m_Line;
        public Unit Source;
        public int Damage = 10;
        public Bullet()
        {
            m_Line = ShapeManager.AddLine();
            m_Line.SetFromAbsoluteEndpoints(new Vector3(.5f, 0, 0), Vector3.Zero);
            m_Line.AttachTo(this, false);
        }
        public void Fire(float angle, Vector3 position)
        {
            this.RotationZ = angle;
            Position = position;
        }

        public float speed = .5f;
        public void Activity()
        {
            Vector3 movement = Vector3.Zero;
            movement.X = (float)Math.Cos(this.RotationZ);
            movement.Y = (float)Math.Sin(this.RotationZ);
            movement.Normalize();
            Position += movement * speed;

            if (!SpriteManager.Camera.IsPointInView(X, Y, Z))
            {
                Destroy();
            }
        }
        public void Destroy()
        {
            ShapeManager.Remove(m_Line);
            RemoveSelfFromListsBelongingTo();
        }
    }
}
